package com.cskaoyan.wordmemorize.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cskaoyan.wordmemorize.converter.AdminLogConverter;
import com.cskaoyan.wordmemorize.dao.entity.OperateLogDO;
import com.cskaoyan.wordmemorize.dao.mapper.OperateLogMapper;
import com.cskaoyan.wordmemorize.dto.admin.OperateLogDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.request.OperateLogPageRequest;
import com.cskaoyan.wordmemorize.service.AdminLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminLogServiceImpl implements AdminLogService {
    @Autowired
    OperateLogMapper operateLogMapper;
    @Autowired
    AdminLogConverter operateLogConverter;
    @Override
    public PageDTO<OperateLogDTO> getOperateLogPage(OperateLogPageRequest request) {
        String keyword = request.getKeyword();
        String dataType = request.getDataType();
        String employeeId = request.getEmployeeId();
        Page<OperateLogDO> page = new Page<>(request.getPageNum(), request.getCount());
        LambdaQueryWrapper<OperateLogDO> queryWrapper1 = new  LambdaQueryWrapper<>();
        if (keyword != null)
            queryWrapper1.like(OperateLogDO::getData, keyword);
        if (dataType != null)
            queryWrapper1.eq(OperateLogDO::getDataType, dataType);
        if (employeeId != null)
            queryWrapper1.eq(OperateLogDO::getEmployeeId, employeeId);
        List<OperateLogDO> operateLogDOS = operateLogMapper.selectList(page, queryWrapper1);
         return operateLogConverter.operationLogPage2PageDTO(operateLogDOS, page.getTotal());

    }
}
